﻿using Google.Protobuf;
using System;
using System.IO;
using Test;

namespace protoctest
{
    class Program
    {
        static void Main(string[] args)
        {
            TestContact t = new TestContact();
            t.ID = 1;
            t.Name = "xiao ming";
            t.Address = "Cheng Du";
            Console.WriteLine($"序列化之前：{t}");

            //序列化操作
            byte[] data = new byte[t.CalculateSize()];
            using (CodedOutputStream cos = new CodedOutputStream(data))
            {
                t.WriteTo(cos);
                //data = cos.to.ToArray();
            }

            //反序列化操作
            TestContact t1 = TestContact.Parser.ParseFrom(data);
            Console.WriteLine($"反序列化得到：{t1}");

            Console.ReadKey();
        }
    }
}
